﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class SequenceOfGivenSum
{
    static void Main()
    {
        try
        {
            List<int> array = new List<int> { 4, 3, 1, 4, 2, 5, 8 };
            List<int> elements = new List<int>();
            int size = array.Count;   
            int sum = 0;
            int index = 0;
            int numbers = 0;
            int S = 11;

            for (int i = 0; i < size; i++)
            {
                for (int j = i; j < size; j++)
                {
                    sum += array[j];
                    index = j;
                    if (S == sum)
                    {
                        while (sum != 0)
                        {
                            sum -= array[j];
                            elements.Add(array[j]);
                            j--;
                        }
                    }
                    j = index;
                }
                sum = 0;
            }
            for (int k = elements.Count - 1; k >= 0; k--)
            {
                Console.Write(" " + elements[k]);
                numbers += elements[k];
                if (numbers == S)
                {
                    Console.Write(";");
                }
            }
            Console.WriteLine();
          
        }
        catch (Exception)
        {
            Console.WriteLine("Wrong data!");
            return;
        }
    }
}